package com.gitee.wsl.mathematics.vector.ext

import com.gitee.wsl.mathematics.base.Mapping2
import com.gitee.wsl.mathematics.base.Mapping3
import com.gitee.wsl.mathematics.base.Mapping4
import com.gitee.wsl.mathematics.vector.vec2.MutableVector2
import com.gitee.wsl.mathematics.vector.vec2.Vector2
import com.gitee.wsl.mathematics.vector.vec3.MutableVector3
import com.gitee.wsl.mathematics.vector.vec3.Vector3
import com.gitee.wsl.mathematics.vector.vec4.MutableVector4
import com.gitee.wsl.mathematics.vector.vec4.Vector4

/** Inverse each components of [this] reduce by [out]. */
private inline fun  <A:Number,T> Vector2<A, *>.inverse(out: Mapping2<A,T>) = mapReduce({a->a.divBy(1)}, out)

/** Inverse each components of [this] reduce by [out]. */
private inline fun <A:Number,T> Vector3<A, *>.inverse(out: Mapping3<A,T>) = mapReduce({a->a.divBy(1)}, out)

/** Inverse each components of [this] reduce by [out]. */
private inline fun <A:Number,T> Vector4<A, *>.inverse(out: Mapping4<A,T>) = mapReduce({a->a.divBy(1)}, out)

/** Create a new [MutableVec2] vector initialized with inversed component values of [this]. */
fun  <A:Number,V:Vector2<A, V>> Vector2<A,V>.inverse() = inverse {a,b-> create(a,b) }

fun  <A:Number,V:Vector3<A, V>> Vector3<A, V>.inverse() = inverse {a,b,c-> create(a,b,c) }

fun  <A:Number,V:Vector4<A, V>> Vector4<A, V>.inverse() = inverse {a,b,c,d-> create(a,b,c,d) }


/** Create a new [MutableVec2] vector initialized with inversed component values of [this]. */
fun  <A:Number,V:Vector2<A, V>> MutableVector2<A, V>.inverse() = inverse { a, b-> set(a,b) }

fun  <A:Number,V:Vector3<A, V>> MutableVector3<A, V>.inverse() = inverse { a, b, c-> set(a,b,c) }

fun  <A:Number,V:Vector4<A, V>> MutableVector4<A, V>.inverse() = inverse { a, b, c, d-> set(a,b,c,d) }